package com.xukai.springboot.controller.sys;

import com.xukai.springboot.entity.response.PageResult;
import com.xukai.springboot.entity.response.ResponseBase;
import com.xukai.springboot.entity.sys.t_sys_authority;
import com.xukai.springboot.entity.sys.t_sys_role;
import com.xukai.springboot.entity.sys.t_sys_user;
import com.xukai.springboot.util.session.SessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(basePath = "api/sys/user", description = "用户管理")
@RestController
@RequestMapping("api/sys/user/*")
public class UserController {


    /**
     * 日志
     */
    private final Logger logger = LoggerFactory.getLogger(UserController.class);


    /**
     * session服务
     */
    @Autowired
    SessionService sessionService;

    /**
     * 获取系统用户列表
     */
    @ApiOperation(value = "获取系统用户列表", notes = "获取系统用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StartIndex", value = "查询起始索引", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query"),
            @ApiImplicitParam(name = "PageSize", value = "分页大小", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query"),
            @ApiImplicitParam(name = "UserName", value = "用户名", required = true, dataType = "string", example = "0", paramType = "query")
    })
    @GetMapping("GetUserList")
    public ResponseBase<PageResult<t_sys_user>> GetUserList(@RequestParam int StartIndex, @RequestParam int PageSize, @RequestParam String UserName) {
        ResponseBase<PageResult<t_sys_user>> result = new ResponseBase<>();
        try {
        } catch (Exception e) {
            logger.error("获取系统用户列表", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 获取康复师列表
     */
    @ApiOperation(value = "获取康复师列表", notes = "获取康复师列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StartIndex", value = "查询起始索引", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query"),
            @ApiImplicitParam(name = "PageSize", value = "分页大小", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query"),
            @ApiImplicitParam(name = "UserName", value = "用户名", required = false, dataType = "string", example = "0", paramType = "query")
    })
    @GetMapping("GetTherapistsList")
    public ResponseBase<PageResult<t_sys_user>> GetTherapistsList(@RequestParam int StartIndex, @RequestParam int PageSize, @RequestParam String UserName) {
        ResponseBase<PageResult<t_sys_user>> result = new ResponseBase<>();
        try {
        } catch (Exception e) {
            logger.error("获取康复师列表", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 获取用户信息
     *
     * @param userID
     * @return
     */
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userID", value = "用户ID", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("GetUserDetial")
    public ResponseBase<t_sys_user> GetUserDetial(@RequestParam int userID) {
        ResponseBase<t_sys_user> result = new ResponseBase<>();
        try {
        } catch (Exception e) {
            logger.error("获取用户详细信息", e);
            result.setStatue(0);
            result.setErrMessage("用户详情获取失败");
        }
        return result;
    }

    /**
     * 获取当前用户信息
     *
     * @return
     */
    @ApiOperation(value = "获取当前用户信息", notes = "获取当前用户信息")
    @GetMapping("GetCurrentUser")
    public ResponseBase<t_sys_user> GetCurrentUser() {
        ResponseBase<t_sys_user> result = new ResponseBase<>();
        try {
            t_sys_user data = (t_sys_user) sessionService.getCurrentUser();
            if (data == null) {
                result.setStatue(0);
                result.setErrMessage("当前用户信息获取失败");
                return result;
            }
            result.setData(data);
        } catch (Exception e) {
            logger.error("当前用户信息获取失败", e);
            result.setStatue(0);
            result.setErrMessage("当前用户信息获取失败");
        }
        return result;
    }

    /**
     * 修改用户信息
     */
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Param", value = "系统用户信息", required = true, dataType = "t_sys_user", paramType = "body")
    })
    @PostMapping("EditSysUser")
    public ResponseBase EditSysUser(@RequestBody t_sys_user Param) {
        ResponseBase result = new ResponseBase();
        try {
        } catch (Exception e) {
            logger.error("修改用户信息", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 新建用户信息
     */
    @ApiOperation(value = "新建用户信息", notes = "新建用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Param", value = "系统用户信息", required = true, dataType = "t_sys_user", paramType = "body")
    })
    @PostMapping("CreateSysUser")
    public ResponseBase<t_sys_user> CreateSysUser(@RequestBody t_sys_user Param) {
        ResponseBase<t_sys_user> result = new ResponseBase<>();
        try {

        } catch (Exception e) {
            logger.error("新建用户信息", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 删除用户信息
     */
    @ApiOperation(value = "删除用户信息", notes = "删除用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserID", value = "用户ID", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query")
    })
    @GetMapping("DelSysUser")
    public ResponseBase DelSysUser(@RequestParam int UserID) {
        ResponseBase result = new ResponseBase();
        try {
        } catch (Exception e) {
            logger.error("删除用户信息", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 获取用户角色列表
     */
    @ApiOperation(value = "获取用户角色列表", notes = "获取用户角色列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserID", value = "用户ID", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query")
    })
    @GetMapping("GetRoleList")
    public ResponseBase<List<t_sys_role>> GetRoleList(@RequestParam int UserID) {
        ResponseBase result = new ResponseBase();
        try {
        } catch (Exception e) {
            logger.error("获取用户角色列表", e);
            result.setStatue(0);
        }
        return result;
    }

    /**
     * 获取用户权限列表
     */
    @ApiOperation(value = "获取用户权限列表", notes = "获取用户权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "UserID", value = "用户ID", required = true, dataType = "int", example = "0", defaultValue = "0", paramType = "query")
    })
    @GetMapping("GetAuthorityList")
    public ResponseBase<List<t_sys_authority>> GetAuthorityList(@RequestParam int UserID) {
        ResponseBase<List<t_sys_authority>> result = new ResponseBase<>();
        try {
        } catch (Exception e) {
            logger.error("获取用户权限列表", e);
            result.setStatue(0);
        }
        return result;
    }
}
